package com.itqf.mybatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * projectName: mybatisgp8
 *
 * @author: 赵伟风
 * time: 2021/7/28 17:35
 * description:基于ibaits的基础上，继续查询操作
 */
public class MyBatisQuery {

    public static void main(String[] args) throws IOException {

        //1.SqlSessionFactoryBuilder new
        SqlSessionFactoryBuilder sessionFactoryBuilder = new SqlSessionFactoryBuilder();

        //2.创建SqlSessionFactory sessionFactoryBuilder.build(配置文件的流)

        String path = "mybatis_config.xml";

        InputStream stream = Resources.getResourceAsStream(path);

        SqlSessionFactory sessionFactory = sessionFactoryBuilder.build(stream);

        //3.sqlSession
        SqlSession sqlSession = sessionFactory.openSession();

        //4.执行sql语句
        /**
         * sqlSession
         *     String statement = mapper.namespace.标签.id  |  Object Parameter
         *     insert
         *     insert
         *     update
         *     update
         *     delete
         *     delete
         *     selectOne   E
         *     selectOne
         *     selectList List<E>
         *     selectList
         */
         List<Map<String,Object>> mapList = sqlSession.selectList("da.queryUser");

         System.out.println("mapList = " + mapList);

         //5.释放资源
         sqlSession.close();

    }

}
